$(function() {
    document.body.onorientationchange = orient;
    var latlng = new google.maps.LatLng(37.7833365, -122.4026377);
    var myOptions = {
	zoom: 16, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    bluedot = new google.maps.MarkerImage('icons/blue.png',
					  new google.maps.Size(9, 9),
					  new google.maps.Point(0, 0),
					  new google.maps.Point(4, 4)); // anchor
    reddot = new google.maps.MarkerImage('icons/red.png',
					  new google.maps.Size(9, 9),
					  new google.maps.Point(0, 0),
					  new google.maps.Point(4, 4)); // anchor
    track = [ ];
    marker = false;
    navigator.geolocation.watchPosition(function(position) {
	var lat = position.coords.latitude;
	var long = position.coords.longitude;
	var myLatLng = new google.maps.LatLng(lat, long);
	map.setCenter(myLatLng);
	track.push(myLatLng);
	var TrackLine = new google.maps.Polyline({
	    path: track,
	    strokeColor: "#0000FF",
	    strokeOpacity: 1.0,
	    strokeWeight: 2
	});
	TrackLine.setMap(map);
	if(!marker) {
	    marker = new google.maps.Marker({
		position: myLatLng, map: map, icon: reddot
	    });
	} else {
	    marker.setPosition(myLatLng);
	}
  });
  setTimeout(orient, 1);
});

function orient() {
  // portrait
  if(window.orientation % 180 == 0) {
    $('body').height(window.navigator.standalone ? 460 : 416);
  // landscape
  } else {
    $('body').height(window.navigator.standalone ? 300 : 268);
  }
  hide_address_bar();
}

function hide_address_bar () {
  setTimeout(function () {
    window.scrollTo(0, 1);
  }, 1);
}
